package com.zc.im.service.user.impl;

import com.zc.im.mapper.user.ZcComInfoMapper;
import com.zc.im.model.user.ZcComInfo;
import com.zc.im.model.user.ZcComInfoExample;
import com.zc.im.service.user.ZcComInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by wangcc on 2017/7/13.
 */
@Service
public class ZcComInfoServiceImpl implements ZcComInfoService {

    @Autowired
    private ZcComInfoMapper zcComInfoMapper;
    private Logger logger =Logger.getLogger(ZcComInfoServiceImpl.class);

    /**
     * 通过uid查询公司信息
     * @param zcComInfoCriteria
     * @return
     */
    @Override
    public ZcComInfo findworkTime(ZcComInfo zcComInfoCriteria) {
        ZcComInfo zcComInfo = null;
        try {
            if (zcComInfoCriteria == null) {
                return zcComInfo;
            }
            ZcComInfoExample example = new ZcComInfoExample();
            ZcComInfoExample.Criteria criteria = example.createCriteria();
            criteria.andUidEqualTo(zcComInfoCriteria.getUid());
            List<ZcComInfo> listZcComInfo = zcComInfoMapper.selectByExample(example);
            if (listZcComInfo == null || listZcComInfo.size()==0) {
                return zcComInfo;
            }
            zcComInfo = listZcComInfo.get(0);
        }catch (Exception  e) {
            logger.error(e.getMessage() , e);
        }
        return zcComInfo;
    }

    /**
     * 通过uid 查询企业所有信息
     * @param zcComInfoId
     * @return
     */
    @Override
    public ZcComInfo findZcComInfoId(Integer zcComInfoId) {
        ZcComInfo zcComInfo = new ZcComInfo();
        if (zcComInfoId == null) {
            logger.error("find zzcComInfoId   is null");
            return zcComInfo;
        }
        ZcComInfoExample example = new ZcComInfoExample();
        ZcComInfoExample.Criteria criteria = example.createCriteria();
        criteria.andUidEqualTo(zcComInfoId);
        try {
            List<ZcComInfo> listZcComInfo = zcComInfoMapper.selectByExample(example);
            if (listZcComInfo == null || listZcComInfo.size() == 0) {
                return zcComInfo;
            }
            zcComInfo = listZcComInfo.get(0);
        }catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return zcComInfo;
    }
}
